﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.TagCloud == "undefined") Axis.View.TagCloud = {};
Axis.View.TagCloud.List = {
    Init: function () {
        this.GetCloundTag();
    },
    GetCloundTag: function () {
        var pData = '{}';
        var thisObj = this;
        $.ajax({
            url: '../TagCloud/Service/ClounbTagService.asmx/GetList',
            type: 'POST',
            data: pData,
            cache: false,
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (pData, textStatus, jqXHR) {
                if (pData !== null)
                    if (pData.d !== null) {
                        try {
                            var data = eval("(" + pData.d + ")");

                            thisObj.BuildCloundTab(data);
                        } catch (e) { 
                        
                        }
                    }

            },
            beforeSend: function (jqXHR, settings) {
            },
            error: function (jqXHR, textStatus, errorThrown) {
            },
            complete: function (XMLHttpRequest, textStatus) {
            }
        });

    },
    BuildCloundTab: function (data) {
        var objThis = this;
        var pattern = '<li class="tag{0}"><a href="../TagCloud/{1}">{2}</a></li>';
        var htmlContent = "";
        $.each(data, function (index, item) {
            htmlContent += $.string.Format(pattern, objThis.GetRandom(1, 5), item.ID, item.Text);
        });
        $("#listCloundTag").html(htmlContent);
    },
    GetRandom: function (min, max) {
        return Math.round((Math.random() * (max - min)) + min);
    }
}
$(function () {
    Axis.View.TagCloud.List.Init();
});